home *** CD-ROM | disk | FTP | other *** search
/ Digital Background Bonanza / Digital Background Bonanza - Disc 1.iso / pc / DBB1.swf / scripts / __Packages / mx / video / NCManager.as < prev    next >
Encoding:
Text File  |  2007-03-09  |  25.9 KB  |  866 lines

  1. class mx.video.NCManager implements mx.video.INCManager
  2. {
  3.    var _timeoutIntervalId;
  4.    var _tryNCIntervalId;
  5.    var _timeout;
  6.    var _nc;
  7.    var _ncConnected;
  8.    var _isRTMP;
  9.    var _serverName;
  10.    var _wrappedURL;
  11.    var _portNumber;
  12.    var _appName;
  13.    var _contentPath;
  14.    var _streamName;
  15.    var _streamLength;
  16.    var _streamWidth;
  17.    var _streamHeight;
  18.    var _streams;
  19.    var _autoSenseBW;
  20.    var fpadZone;
  21.    var _payload;
  22.    var _connTypeCounter;
  23.    var _bitrate;
  24.    var _owner;
  25.    var _protocol;
  26.    var _smilMgr;
  27.    var mc;
  28.    var _ncUri;
  29.    var _fpadMgr;
  30.    var fallbackServerName;
  31.    var _tryNC;
  32.    static var version = "1.0.1.10";
  33.    static var shortVersion = "1.0.1";
  34.    var DEFAULT_TIMEOUT = 60000;
  35.    static var RTMP_CONN = [{protocol:"rtmp:/",port:"1935"},{protocol:"rtmp:/",port:"443"},{protocol:"rtmpt:/",port:"80"},{protocol:"rtmps:/",port:"443"}];
  36.    function NCManager()
  37.    {
  38.       this.initNCInfo();
  39.       this.initOtherInfo();
  40.       this._timeoutIntervalId = 0;
  41.       this._tryNCIntervalId = 0;
  42.       this._timeout = this.DEFAULT_TIMEOUT;
  43.       this._nc = undefined;
  44.       this._ncConnected = false;
  45.    }
  46.    function initNCInfo()
  47.    {
  48.       this._isRTMP = undefined;
  49.       this._serverName = undefined;
  50.       this._wrappedURL = undefined;
  51.       this._portNumber = undefined;
  52.       this._appName = undefined;
  53.    }
  54.    function initOtherInfo()
  55.    {
  56.       this._contentPath = undefined;
  57.       this._streamName = undefined;
  58.       this._streamLength = undefined;
  59.       this._streamWidth = undefined;
  60.       this._streamHeight = undefined;
  61.       this._streams = undefined;
  62.       this._autoSenseBW = false;
  63.       this.fpadZone = undefined;
  64.       this._payload = 0;
  65.       this._connTypeCounter = 0;
  66.       this.cleanConns();
  67.    }
  68.    function getTimeout()
  69.    {
  70.       return this._timeout;
  71.    }
  72.    function setTimeout(t)
  73.    {
  74.       this._timeout = t;
  75.       if(this._timeoutIntervalId != 0)
  76.       {
  77.          clearInterval(this._timeoutIntervalId);
  78.          this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  79.       }
  80.    }
  81.    function getBitrate()
  82.    {
  83.       return this._bitrate;
  84.    }
  85.    function setBitrate(b)
  86.    {
  87.       if(this._isRTMP == undefined || !this._isRTMP)
  88.       {
  89.          this._bitrate = b;
  90.       }
  91.    }
  92.    function getVideoPlayer()
  93.    {
  94.       return this._owner;
  95.    }
  96.    function setVideoPlayer(v)
  97.    {
  98.       this._owner = v;
  99.    }
  100.    function getNetConnection()
  101.    {
  102.       return this._nc;
  103.    }
  104.    function getStreamName()
  105.    {
  106.       return this._streamName;
  107.    }
  108.    function isRTMP()
  109.    {
  110.       return this._isRTMP;
  111.    }
  112.    function getStreamLength()
  113.    {
  114.       return this._streamLength;
  115.    }
  116.    function getStreamWidth()
  117.    {
  118.       return this._streamWidth;
  119.    }
  120.    function getStreamHeight()
  121.    {
  122.       return this._streamHeight;
  123.    }
  124.    function connectToURL(url)
  125.    {
  126.       this.initOtherInfo();
  127.       this._contentPath = url;
  128.       if(this._contentPath == null || this._contentPath == undefined || this._contentPath == "")
  129.       {
  130.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH);
  131.       }
  132.       var _loc2_ = this.parseURL(this._contentPath);
  133.       if(_loc2_.streamName == undefined || _loc2_.streamName == "")
  134.       {
  135.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  136.       }
  137.       if(_loc2_.isRTMP)
  138.       {
  139.          var _loc3_ = this.canReuseOldConnection(_loc2_);
  140.          this._isRTMP = true;
  141.          this._protocol = _loc2_.protocol;
  142.          this._streamName = _loc2_.streamName;
  143.          this._serverName = _loc2_.serverName;
  144.          this._wrappedURL = _loc2_.wrappedURL;
  145.          this._portNumber = _loc2_.portNumber;
  146.          this._appName = _loc2_.appName;
  147.          if(this._appName == undefined || this._appName == "" || this._streamName == undefined || this._streamName == "")
  148.          {
  149.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  150.          }
  151.          this._autoSenseBW = this._streamName.indexOf(",") >= 0;
  152.          return _loc3_ || this.connectRTMP();
  153.       }
  154.       if(_loc2_.streamName.indexOf("?") < 0 && _loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  155.       {
  156.          _loc3_ = this.canReuseOldConnection(_loc2_);
  157.          this._isRTMP = false;
  158.          this._streamName = _loc2_.streamName;
  159.          return _loc3_ || this.connectHTTP();
  160.       }
  161.       if(_loc2_.streamName.indexOf("/fms/fpad") >= 0)
  162.       {
  163.          try
  164.          {
  165.             return this.connectFPAD(_loc2_.streamName);
  166.          }
  167.          catch(err:Error)
  168.          {
  169.          }
  170.       }
  171.       this._smilMgr = new mx.video.SMILManager(this);
  172.       return this._smilMgr.connectXML(_loc2_.streamName);
  173.    }
  174.    function connectAgain()
  175.    {
  176.       var _loc2_ = this._appName.indexOf("/");
  177.       if(_loc2_ < 0)
  178.       {
  179.          _loc2_ = this._streamName.indexOf("/");
  180.          if(_loc2_ >= 0)
  181.          {
  182.             this._appName += "/";
  183.             this._appName += this._streamName.slice(0,_loc2_);
  184.             this._streamName = this._streamName.slice(_loc2_ + 1);
  185.          }
  186.          return false;
  187.       }
  188.       var _loc3_ = this._appName.slice(_loc2_ + 1);
  189.       _loc3_ += "/";
  190.       _loc3_ += this._streamName;
  191.       this._streamName = _loc3_;
  192.       this._appName = this._appName.slice(0,_loc2_);
  193.       this.close();
  194.       this._payload = 0;
  195.       this._connTypeCounter = 0;
  196.       this.cleanConns();
  197.       this.connectRTMP();
  198.       return true;
  199.    }
  200.    function reconnect()
  201.    {
  202.       if(!this._isRTMP)
  203.       {
  204.          throw new Error("Cannot call reconnect on an http connection");
  205.       }
  206.       this._nc.onStatus = function(info)
  207.       {
  208.          this.mc.reconnectOnStatus(this,info);
  209.       };
  210.       this._nc.onBWDone = function()
  211.       {
  212.          this.mc.onReconnected();
  213.       };
  214.       this._nc.connect(this._ncUri,false);
  215.    }
  216.    function onReconnected()
  217.    {
  218.       delete this._nc.onStatus;
  219.       delete this._nc.onBWDone;
  220.       this._ncConnected = true;
  221.       this._owner.ncReconnected();
  222.    }
  223.    function close()
  224.    {
  225.       if(this._nc)
  226.       {
  227.          this._nc.close();
  228.          this._ncConnected = false;
  229.       }
  230.    }
  231.    function helperDone(helper, success)
  232.    {
  233.       if(!success)
  234.       {
  235.          this._nc = undefined;
  236.          this._ncConnected = false;
  237.          this._owner.ncConnected();
  238.          this._smilMgr = undefined;
  239.          this._fpadMgr = undefined;
  240.          return undefined;
  241.       }
  242.       var _loc2_ = undefined;
  243.       var _loc4_ = undefined;
  244.       if(helper == this._fpadMgr)
  245.       {
  246.          _loc4_ = this._fpadMgr.rtmpURL;
  247.          this._fpadMgr = undefined;
  248.          _loc2_ = this.parseURL(_loc4_);
  249.          this._isRTMP = _loc2_.isRTMP;
  250.          this._protocol = _loc2_.protocol;
  251.          this._serverName = _loc2_.serverName;
  252.          this._portNumber = _loc2_.portNumber;
  253.          this._wrappedURL = _loc2_.wrappedURL;
  254.          this._appName = _loc2_.appName;
  255.          this._streamName = _loc2_.streamName;
  256.          var _loc5_ = this.fpadZone;
  257.          this.fpadZone = -1;
  258.          this.connectRTMP();
  259.          this.fpadZone = _loc5_;
  260.          return undefined;
  261.       }
  262.       if(helper != this._smilMgr)
  263.       {
  264.          return undefined;
  265.       }
  266.       this._streamWidth = this._smilMgr.width;
  267.       this._streamHeight = this._smilMgr.height;
  268.       _loc4_ = this._smilMgr.baseURLAttr[0];
  269.       if(_loc4_ != undefined && _loc4_ != "")
  270.       {
  271.          if(_loc4_.charAt(_loc4_.length - 1) != "/")
  272.          {
  273.             _loc4_ += "/";
  274.          }
  275.          _loc2_ = this.parseURL(_loc4_);
  276.          this._isRTMP = _loc2_.isRTMP;
  277.          this._streamName = _loc2_.streamName;
  278.          if(this._isRTMP)
  279.          {
  280.             this._protocol = _loc2_.protocol;
  281.             this._serverName = _loc2_.serverName;
  282.             this._portNumber = _loc2_.portNumber;
  283.             this._wrappedURL = _loc2_.wrappedURL;
  284.             this._appName = _loc2_.appName;
  285.             if(this._appName == undefined || this._appName == "")
  286.             {
  287.                this._smilMgr = undefined;
  288.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  289.             }
  290.             if(this._smilMgr.baseURLAttr.length > 1)
  291.             {
  292.                _loc2_ = this.parseURL(this._smilMgr.baseURLAttr[1]);
  293.                if(_loc2_.serverName != undefined)
  294.                {
  295.                   this.fallbackServerName = _loc2_.serverName;
  296.                }
  297.             }
  298.          }
  299.       }
  300.       this._streams = this._smilMgr.videoTags;
  301.       this._smilMgr = undefined;
  302.       var _loc3_ = 0;
  303.       while(_loc3_ < this._streams.length)
  304.       {
  305.          _loc4_ = this._streams[_loc3_].src;
  306.          _loc2_ = this.parseURL(_loc4_);
  307.          if(this._isRTMP == undefined)
  308.          {
  309.             this._isRTMP = _loc2_.isRTMP;
  310.             if(this._isRTMP)
  311.             {
  312.                this._protocol = _loc2_.protocol;
  313.                if(this._streams.length > 1)
  314.                {
  315.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute RTMP URLs, must use meta tag base attribute.");
  316.                }
  317.                this._serverName = _loc2_.serverName;
  318.                this._portNumber = _loc2_.portNumber;
  319.                this._wrappedURL = _loc2_.wrappedURL;
  320.                this._appName = _loc2_.appName;
  321.                if(this._appName == undefined || this._appName == "")
  322.                {
  323.                   throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Base RTMP URL must include application name: " + _loc4_);
  324.                }
  325.             }
  326.             else if(_loc2_.streamName.indexOf("/fms/fpad") >= 0 && this._streams.length > 1)
  327.             {
  328.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"Cannot switch between multiple absolute fpad URLs, must use meta tag base attribute.");
  329.             }
  330.          }
  331.          else if(this._streamName != undefined && this._streamName != "" && !_loc2_.isRelative && this._streams.length > 1)
  332.          {
  333.             throw new mx.video.VideoError(mx.video.VideoError.INVALID_XML,"When using meta tag base attribute, cannot use absolute URLs for video or ref tag src attributes.");
  334.          }
  335.          this._streams[_loc3_].parseResults = _loc2_;
  336.          _loc3_ = _loc3_ + 1;
  337.       }
  338.       this._autoSenseBW = this._streams.length > 1;
  339.       if(!this._autoSenseBW)
  340.       {
  341.          if(this._streamName != undefined)
  342.          {
  343.             this._streamName += this._streams[0].parseResults.streamName;
  344.          }
  345.          else
  346.          {
  347.             this._streamName = this._streams[0].parseResults.streamName;
  348.          }
  349.          this._streamLength = this._streams[0].dur;
  350.       }
  351.       if(this._isRTMP)
  352.       {
  353.          this.connectRTMP();
  354.       }
  355.       else if(this._streamName != undefined && this._streamName.indexOf("/fms/fpad") >= 0)
  356.       {
  357.          this.connectFPAD(this._streamName);
  358.       }
  359.       else
  360.       {
  361.          if(this._autoSenseBW)
  362.          {
  363.             this.bitrateMatch();
  364.          }
  365.          this.connectHTTP();
  366.          this._owner.ncConnected();
  367.       }
  368.    }
  369.    function bitrateMatch()
  370.    {
  371.       var _loc3_ = undefined;
  372.       var _loc4_ = this._bitrate;
  373.       if(isNaN(_loc4_))
  374.       {
  375.          _loc4_ = 0;
  376.       }
  377.       var _loc2_ = 0;
  378.       while(_loc2_ < this._streams.length)
  379.       {
  380.          if(isNaN(this._streams[_loc2_].bitrate) || _loc4_ >= this._streams[_loc2_].bitrate)
  381.          {
  382.             _loc3_ = _loc2_;
  383.             break;
  384.          }
  385.          _loc2_ = _loc2_ + 1;
  386.       }
  387.       if(isNaN(_loc3_))
  388.       {
  389.          throw new mx.video.VideoError(mx.video.VideoError.NO_BITRATE_MATCH);
  390.       }
  391.       if(this._streamName != undefined)
  392.       {
  393.          this._streamName += this._streams[_loc3_].src;
  394.       }
  395.       else
  396.       {
  397.          this._streamName = this._streams[_loc3_].src;
  398.       }
  399.       this._streamLength = this._streams[_loc3_].dur;
  400.    }
  401.    function parseURL(url)
  402.    {
  403.       var _loc2_ = new Object();
  404.       var _loc3_ = 0;
  405.       var _loc4_ = url.indexOf(":/",_loc3_);
  406.       if(_loc4_ >= 0)
  407.       {
  408.          _loc4_ += 2;
  409.          _loc2_.protocol = url.slice(_loc3_,_loc4_);
  410.          _loc2_.isRelative = false;
  411.       }
  412.       else
  413.       {
  414.          _loc2_.isRelative = true;
  415.       }
  416.       if(_loc2_.protocol != undefined && (_loc2_.protocol == "rtmp:/" || _loc2_.protocol == "rtmpt:/" || _loc2_.protocol == "rtmps:/"))
  417.       {
  418.          _loc2_.isRTMP = true;
  419.          _loc3_ = _loc4_;
  420.          if(url.charAt(_loc3_) == "/")
  421.          {
  422.             _loc3_ = _loc3_ + 1;
  423.             var _loc7_ = url.indexOf(":",_loc3_);
  424.             var _loc8_ = url.indexOf("/",_loc3_);
  425.             if(_loc8_ < 0)
  426.             {
  427.                if(_loc7_ < 0)
  428.                {
  429.                   _loc2_.serverName = url.slice(_loc3_);
  430.                }
  431.                else
  432.                {
  433.                   _loc4_ = _loc7_;
  434.                   _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  435.                   _loc3_ = _loc4_ + 1;
  436.                   _loc2_.serverName = url.slice(_loc3_);
  437.                }
  438.                return _loc2_;
  439.             }
  440.             if(_loc7_ >= 0 && _loc7_ < _loc8_)
  441.             {
  442.                _loc4_ = _loc7_;
  443.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  444.                _loc3_ = _loc4_ + 1;
  445.                _loc4_ = _loc8_;
  446.                _loc2_.portNumber = url.slice(_loc3_,_loc4_);
  447.             }
  448.             else
  449.             {
  450.                _loc4_ = _loc8_;
  451.                _loc2_.serverName = url.slice(_loc3_,_loc4_);
  452.             }
  453.             _loc3_ = _loc4_ + 1;
  454.          }
  455.          if(url.charAt(_loc3_) == "?")
  456.          {
  457.             var _loc9_ = url.slice(_loc3_ + 1);
  458.             var _loc6_ = this.parseURL(_loc9_);
  459.             if(_loc6_.protocol == undefined || !_loc6_.isRTMP)
  460.             {
  461.                throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,url);
  462.             }
  463.             _loc2_.wrappedURL = "?";
  464.             _loc2_.wrappedURL += _loc6_.protocol;
  465.             if(_loc6_.serverName != undefined)
  466.             {
  467.                _loc2_.wrappedURL += "/";
  468.                _loc2_.wrappedURL += _loc6_.serverName;
  469.             }
  470.             if(_loc6_.wrappedURL != undefined)
  471.             {
  472.                _loc2_.wrappedURL += "/?";
  473.                _loc2_.wrappedURL += _loc6_.wrappedURL;
  474.             }
  475.             _loc2_.appName = _loc6_.appName;
  476.             _loc2_.streamName = _loc6_.streamName;
  477.             return _loc2_;
  478.          }
  479.          _loc4_ = url.indexOf("/",_loc3_);
  480.          if(_loc4_ < 0)
  481.          {
  482.             _loc2_.appName = url.slice(_loc3_);
  483.             return _loc2_;
  484.          }
  485.          _loc2_.appName = url.slice(_loc3_,_loc4_);
  486.          _loc3_ = _loc4_ + 1;
  487.          _loc4_ = url.indexOf("/",_loc3_);
  488.          if(_loc4_ < 0)
  489.          {
  490.             _loc2_.streamName = url.slice(_loc3_);
  491.             if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  492.             {
  493.                _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  494.             }
  495.             return _loc2_;
  496.          }
  497.          _loc2_.appName += "/";
  498.          _loc2_.appName += url.slice(_loc3_,_loc4_);
  499.          _loc3_ = _loc4_ + 1;
  500.          _loc2_.streamName = url.slice(_loc3_);
  501.          if(_loc2_.streamName.slice(-4).toLowerCase() == ".flv")
  502.          {
  503.             _loc2_.streamName = _loc2_.streamName.slice(0,-4);
  504.          }
  505.       }
  506.       else
  507.       {
  508.          _loc2_.isRTMP = false;
  509.          _loc2_.streamName = url;
  510.       }
  511.       return _loc2_;
  512.    }
  513.    function canReuseOldConnection(parseResults)
  514.    {
  515.       if(this._nc == undefined || this._nc == null || !this._ncConnected)
  516.       {
  517.          return false;
  518.       }
  519.       if(!parseResults.isRTMP)
  520.       {
  521.          if(!this._isRTMP)
  522.          {
  523.             return true;
  524.          }
  525.          this._owner.close();
  526.          this._nc = undefined;
  527.          this._ncConnected = false;
  528.          this.initNCInfo();
  529.          return false;
  530.       }
  531.       if(this._isRTMP)
  532.       {
  533.          if(parseResults.serverName == this._serverName && parseResults.appName == this._appName && parseResults.protocol == this._protocol && parseResults.portNumber == this._portNumber && parseResults.wrappedURL == this._wrappedURL)
  534.          {
  535.             return true;
  536.          }
  537.          this._owner.close();
  538.          this._nc = undefined;
  539.          this._ncConnected = false;
  540.       }
  541.       this.initNCInfo();
  542.       return false;
  543.    }
  544.    function connectHTTP()
  545.    {
  546.       this._nc = new NetConnection();
  547.       this._nc.connect(null);
  548.       this._ncConnected = true;
  549.       return true;
  550.    }
  551.    function connectRTMP()
  552.    {
  553.       clearInterval(this._timeoutIntervalId);
  554.       this._timeoutIntervalId = setInterval(this,"_onFCSConnectTimeOut",this._timeout);
  555.       this._tryNC = new Array();
  556.       var _loc2_ = 0;
  557.       while(_loc2_ < mx.video.NCManager.RTMP_CONN.length)
  558.       {
  559.          this._tryNC[_loc2_] = new NetConnection();
  560.          if(this.fpadZone != undefined && this.fpadZone != null)
  561.          {
  562.             this._tryNC[_loc2_].fpadZone = this.fpadZone;
  563.          }
  564.          this._tryNC[_loc2_].mc = this;
  565.          this._tryNC[_loc2_].pending = false;
  566.          this._tryNC[_loc2_].connIndex = _loc2_;
  567.          this._tryNC[_loc2_].onBWDone = function(p_bw)
  568.          {
  569.             this.mc.onConnected(this,p_bw);
  570.          };
  571.          this._tryNC[_loc2_].onBWCheck = function()
  572.          {
  573.             return ++this.mc._payload;
  574.          };
  575.          this._tryNC[_loc2_].onStatus = function(info)
  576.          {
  577.             this.mc.connectOnStatus(this,info);
  578.          };
  579.          _loc2_ = _loc2_ + 1;
  580.       }
  581.       this.nextConnect();
  582.       return false;
  583.    }
  584.    function connectFPAD(url)
  585.    {
  586.       var _loc7_ = undefined;
  587.       var _loc5_ = undefined;
  588.       var _loc6_ = undefined;
  589.       var _loc2_ = url.indexOf("?");
  590.       while(_loc2_ >= 0)
  591.       {
  592.          _loc2_ = _loc2_ + 1;
  593.          var _loc4_ = url.indexOf("&",_loc2_);
  594.          if(url.substr(_loc2_,4).toLowerCase() == "uri=")
  595.          {
  596.             _loc7_ = url.slice(0,_loc2_);
  597.             _loc2_ += 4;
  598.             if(_loc4_ >= 0)
  599.             {
  600.                _loc5_ = url.slice(_loc2_,_loc4_);
  601.                _loc6_ = url.slice(_loc4_);
  602.             }
  603.             else
  604.             {
  605.                _loc5_ = url.slice(_loc2_);
  606.                _loc6_ = "";
  607.             }
  608.             break;
  609.          }
  610.          _loc2_ = _loc4_;
  611.       }
  612.       if(_loc2_ < 0)
  613.       {
  614.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url must include uri parameter: " + url);
  615.       }
  616.       var _loc8_ = this.parseURL(_loc5_);
  617.       if(!_loc8_.isRTMP)
  618.       {
  619.          throw new mx.video.VideoError(mx.video.VideoError.INVALID_CONTENT_PATH,"fpad url uri parameter must be rtmp url: " + url);
  620.       }
  621.       this._fpadMgr = new mx.video.FPADManager(this);
  622.       return this._fpadMgr.connectXML(_loc7_,_loc5_,_loc6_,_loc8_);
  623.    }
  624.    function nextConnect()
  625.    {
  626.       clearInterval(this._tryNCIntervalId);
  627.       this._tryNCIntervalId = 0;
  628.       var _loc4_ = undefined;
  629.       var _loc3_ = undefined;
  630.       if(this._connTypeCounter == 0)
  631.       {
  632.          _loc4_ = this._protocol;
  633.          if(this._portNumber != undefined)
  634.          {
  635.             _loc3_ = this._portNumber;
  636.          }
  637.          else
  638.          {
  639.             var _loc2_ = 0;
  640.             while(_loc2_ < mx.video.NCManager.RTMP_CONN.length)
  641.             {
  642.                if(_loc4_ == mx.video.NCManager.RTMP_CONN[_loc2_].protocol)
  643.                {
  644.                   _loc3_ = mx.video.NCManager.RTMP_CONN[_loc2_].port;
  645.                   break;
  646.                }
  647.                _loc2_ = _loc2_ + 1;
  648.             }
  649.          }
  650.       }
  651.       else
  652.       {
  653.          _loc4_ = mx.video.NCManager.RTMP_CONN[this._connTypeCounter].protocol;
  654.          _loc3_ = mx.video.NCManager.RTMP_CONN[this._connTypeCounter].port;
  655.       }
  656.       var _loc5_ = _loc4_ + (this._serverName != undefined ? "/" + this._serverName + ":" + _loc3_ + "/" : "") + (this._wrappedURL != undefined ? this._wrappedURL + "/" : "") + this._appName;
  657.       this._tryNC[this._connTypeCounter].pending = true;
  658.       this._tryNC[this._connTypeCounter].connect(_loc5_,this._autoSenseBW);
  659.       if(this._connTypeCounter < mx.video.NCManager.RTMP_CONN.length - 1)
  660.       {
  661.          this._connTypeCounter = this._connTypeCounter + 1;
  662.          this._tryNCIntervalId = setInterval(this,"nextConnect",1500);
  663.       }
  664.    }
  665.    function cleanConns()
  666.    {
  667.       clearInterval(this._tryNCIntervalId);
  668.       this._tryNCIntervalId = 0;
  669.       if(this._tryNC != undefined)
  670.       {
  671.          var _loc2_ = 0;
  672.          while(_loc2_ < this._tryNC.length)
  673.          {
  674.             if(this._tryNC[_loc2_] != undefined)
  675.             {
  676.                delete this._tryNC[_loc2_].onStatus;
  677.                if(this._tryNC[_loc2_].pending)
  678.                {
  679.                   this._tryNC[_loc2_].onStatus = function(info)
  680.                   {
  681.                      this.mc.disconnectOnStatus(this,info);
  682.                   };
  683.                }
  684.                else
  685.                {
  686.                   delete this._tryNC[_loc2_].onStatus;
  687.                   this._tryNC[_loc2_].close();
  688.                }
  689.             }
  690.             delete this._tryNC[_loc2_];
  691.             _loc2_ = _loc2_ + 1;
  692.          }
  693.          delete this._tryNC;
  694.       }
  695.    }
  696.    function tryFallBack()
  697.    {
  698.       if(this._serverName == this.fallbackServerName || this.fallbackServerName == undefined || this.fallbackServerName == null)
  699.       {
  700.          delete this._nc;
  701.          this._nc = undefined;
  702.          this._ncConnected = false;
  703.          this._owner.ncConnected();
  704.       }
  705.       else
  706.       {
  707.          this._connTypeCounter = 0;
  708.          this.cleanConns();
  709.          this._serverName = this.fallbackServerName;
  710.          this.connectRTMP();
  711.       }
  712.    }
  713.    function onConnected(p_nc, p_bw)
  714.    {
  715.       clearInterval(this._timeoutIntervalId);
  716.       this._timeoutIntervalId = 0;
  717.       delete p_nc.onBWDone;
  718.       delete p_nc.onBWCheck;
  719.       delete p_nc.onStatus;
  720.       this._nc = p_nc;
  721.       this._ncUri = this._nc.uri;
  722.       this._ncConnected = true;
  723.       if(this._autoSenseBW)
  724.       {
  725.          this._bitrate = p_bw * 1024;
  726.          if(this._streams != undefined)
  727.          {
  728.             this.bitrateMatch();
  729.          }
  730.          else
  731.          {
  732.             var _loc3_ = this._streamName.split(",");
  733.             var _loc2_ = 0;
  734.             while(_loc2_ < _loc3_.length)
  735.             {
  736.                var _loc4_ = mx.video.NCManager.stripFrontAndBackWhiteSpace(_loc3_[_loc2_]);
  737.                if(_loc2_ + 1 >= _loc3_.length)
  738.                {
  739.                   this._streamName = _loc4_;
  740.                   break;
  741.                }
  742.                if(p_bw <= Number(_loc3_[_loc2_ + 1]))
  743.                {
  744.                   this._streamName = _loc4_;
  745.                   break;
  746.                }
  747.                _loc2_ += 2;
  748.             }
  749.             if(this._streamName.slice(-4).toLowerCase() == ".flv")
  750.             {
  751.                this._streamName = this._streamName.slice(0,-4);
  752.             }
  753.          }
  754.       }
  755.       if(!this._owner.isLive && this._streamLength == undefined)
  756.       {
  757.          var _loc6_ = new Object();
  758.          _loc6_.mc = this;
  759.          _loc6_.onResult = function(length)
  760.          {
  761.             this.mc.getStreamLengthResult(length);
  762.          };
  763.          this._nc.call("getStreamLength",_loc6_,this._streamName);
  764.       }
  765.       else
  766.       {
  767.          this._owner.ncConnected();
  768.       }
  769.    }
  770.    function connectOnStatus(target, info)
  771.    {
  772.       target.pending = false;
  773.       if(info.code == "NetConnection.Connect.Success")
  774.       {
  775.          this._nc = this._tryNC[target.connIndex];
  776.          this._tryNC[target.connIndex] = undefined;
  777.          this.cleanConns();
  778.       }
  779.       else if((info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected") && target.connIndex == mx.video.NCManager.RTMP_CONN.length - 1)
  780.       {
  781.          if(!this.connectAgain())
  782.          {
  783.             this.tryFallBack();
  784.          }
  785.       }
  786.    }
  787.    function reconnectOnStatus(target, info)
  788.    {
  789.       if(info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Rejected")
  790.       {
  791.          delete this._nc;
  792.          this._nc = undefined;
  793.          this._ncConnected = false;
  794.          this._owner.ncReconnected();
  795.       }
  796.    }
  797.    function disconnectOnStatus(target, info)
  798.    {
  799.       if(info.code == "NetConnection.Connect.Success")
  800.       {
  801.          delete target.onStatus;
  802.          target.close();
  803.       }
  804.    }
  805.    function getStreamLengthResult(length)
  806.    {
  807.       if(length > 0)
  808.       {
  809.          this._streamLength = length;
  810.       }
  811.       this._owner.ncConnected();
  812.    }
  813.    function _onFCSConnectTimeOut()
  814.    {
  815.       this.cleanConns();
  816.       this._nc = undefined;
  817.       this._ncConnected = false;
  818.       if(!this.connectAgain())
  819.       {
  820.          this._owner.ncConnected();
  821.       }
  822.    }
  823.    static function stripFrontAndBackWhiteSpace(p_str)
  824.    {
  825.       var _loc1_ = undefined;
  826.       var _loc2_ = p_str.length;
  827.       var _loc4_ = 0;
  828.       var _loc5_ = _loc2_;
  829.       _loc1_ = 0;
  830.       while(_loc1_ < _loc2_)
  831.       {
  832.          switch(p_str.charCodeAt(_loc1_))
  833.          {
  834.             case 9:
  835.             case 10:
  836.             case 13:
  837.             case 32:
  838.                break;
  839.             default:
  840.                _loc4_ = _loc1_;
  841.          }
  842.          _loc1_ = _loc1_ + 1;
  843.       }
  844.       _loc1_ = _loc2_;
  845.       while(_loc1_ >= 0)
  846.       {
  847.          switch(p_str.charCodeAt(_loc1_))
  848.          {
  849.             case 9:
  850.             case 10:
  851.             case 13:
  852.             case 32:
  853.                break;
  854.             default:
  855.                _loc5_ = _loc1_ + 1;
  856.          }
  857.          _loc1_ = _loc1_ - 1;
  858.       }
  859.       if(_loc5_ <= _loc4_)
  860.       {
  861.          return "";
  862.       }
  863.       return p_str.slice(_loc4_,_loc5_);
  864.    }
  865. }
  866.